import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';

@Injectable()
export class DataService {
  constructor(public http: HttpClient) {
  }

  geCityData(): Observable<any> {
    return this.http.get('../assets/data/city-data.json', { withCredentials: false })
      .pipe(
        tap(data => data),
        catchError(this.handleError)
      );
  }

  private handleError(error: Response | any) {
    let errMsg: string;
    debugger
    if (!error.ok) {
      errMsg = "Can't connect to server. Please try again later.";
    } else {
      errMsg = error.message ? error.message : error.toString();
    }
    return Promise.reject(errMsg);
  }

}